mui.getJSON("amap_region.json", {}, function(data) {
	var str = '';
	$.each(data.RECORDS, function(idx, obj) {

		if(obj.citycode == null) {
			str += '</div><div class="provincial Optional iconfont" data-adcode="' + obj.adcode + '">' + obj.name + '</div><div class="citylist">';
		} else {
			if(obj.citycode != data.RECORDS[idx - 1].citycode) {

				str += '<div class="city Optional iconfont" data-adcode="' + obj.adcode + '">' + obj.name + '</div><div class = "countylist"> ';
			} else {
				str += '<div class="county" data-adcode="' + obj.adcode + '">' + obj.name + '</div>';
			}
			//						console.log(idx + '  ' + data.RECORDS.length)
			if(idx < data.RECORDS.length - 1) {
				if(obj.citycode != data.RECORDS[idx + 1].citycode) {
					str += '</div>';
				}
			}

		}
	})

	$(".citybox").html(str);
	$(".citylist").hide();
	$(".countylist").hide()
	$(".provincial,.city").on("tap", function() {
		$(this).next().slideToggle(500);
		$(this).toggleClass("active");
	});

	//下拉列表内选择
	$(".county").on("tap", function() {
		console.log($(this).attr("data-adcode") + '  ' + $(this).parent().prev().html() + ' ' + $(this).html());
		localStorage.setItem("CityAdcode", $(this).attr("data-adcode"));
		localStorage.setItem("CityName", $(this).parent().prev().html() + ' ' + $(this).html());
		window.history.go(-1);
	});

	$(".cityblock").on("tap", function() {
		//块状城市选择
		console.log($(this).attr("data-adcode") + '  ' + $(this).html());
		localStorage.setItem("CityAdcode", $(this).attr("data-adcode"));
		localStorage.setItem("CityName", $(this).html());
		window.history.go(-1);
	})
})

$(".seachmenu").on("tap", function() {
	//点击搜索
	if($(".cityseach").val() != '') {
		$("#seachResult").empty();

		mui.getJSON("amap_region.json", {}, function(data) {
			var seachkey = $(".cityseach").val()
			$.each(data.RECORDS, function(idx, obj) {
				var str = obj.name;
				if(str.search(seachkey) >= 0) {
					console.log(obj.name);
					$("#seachResult").append('<div class="cityblock" data-adcode="' + obj.adcode + '">' + obj.name + '</div>')
				}

			});
		});
	} else {
		mui.toast("请输入搜索关键字!");
	}

})

//新浪api的接口
//var thiscity = remote_ip_info['city'];
//mui.toast(thiscity);
if(thiscity == ''){
	$("#nowcity").html('<div class="Refreshcity" >获取失败</div>');
}else{
//	$("#nowcity").html('<div class="cityblock" >' + thiscity + '</div>')
}
//
//var map = new BMap.Map("allmap");
//var longitude, latitude;
//navigator.geolocation.getCurrentPosition(function(position) {
//	longitude = position.coords.longitude;
//	latitude = position.coords.latitude;
//});
//setTimeout(function() {
//	refundcity()
//}, 3000);
//
//function refundcity(){
//	var gpsPoint = new BMap.Point(longitude, latitude);
//	BMap.Convertor.translate(gpsPoint, 0, function(point) {
//		var geoc = new BMap.Geocoder();
//		geoc.getLocation(point, function(rs) {
//			var addComp = rs.addressComponents;
//			if(addComp.city == '') {
//				$("#nowcity").html('<div class="Refreshcity" >点击重新获取</div>');
//			} else {
//				$("#nowcity").html('<div class="cityblock" >' + addComp.city + '</div>')
//			}
//			$(".Refreshcity").on(function(){
//	Refreshcity()
//})
//
//			mui.toast(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
//		});
//	});
//}
//
//
